package com.zhongwang.business.module.estimateBudgetAccountingManage.service;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.GetDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.SynchronizeDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.VwPdmWorkingHoursModel;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.redis.MatDescModel;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 徐一贺
 * @className SynchronizeDataService
 * @description 同步数据业务逻辑层
 * @date 2020/12/16 18:15
 * @versron ver 1.0
 */
@Log4j2
@Service
public class SynchronizeDataService {

    @Autowired
    private GetDataDao dao;
    @Autowired
    private SynchronizeDataDao syncDao;

    /**
     * synchronizeData 开始同步数据
     *
     * @author 徐一贺
     * @date 2020/12/16 19:02
     */
    public void synchronizeData() {
        try {
            List<MatDescModel> list = dao.findMatDesc();
            ObjectMapper mapper = new ObjectMapper();
            list.forEach(item -> {
                try {
                    syncDao.setKey(item.getMatDesc(), mapper.writeValueAsString(item));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("同步数据错误：" + ex.getMessage());
        }


//        try {
//            VwPdmWorkingHoursModel condition = new VwPdmWorkingHoursModel();
//            condition.setIsDel(0);
//            condition.setStatus(3);
//            List<VwPdmWorkingHoursModel> list = dao.findDesignWorkingHoursListByCondition(condition);
//            ObjectMapper mapper = new ObjectMapper();
//            list.forEach(item -> {
//                try {
//                    syncDao.setKey(item.getCosSheetId().toString(), mapper.writeValueAsString(item));
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            });
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            log.error("同步数据错误：" + ex.getMessage());
//        }
    }
}
